<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@page import="java.util.HashMap"%>
<%@ include file="/WEB-INF/views/tag.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>修改用户信息</title>
<LINK rel="stylesheet" type="text/css" href="${baseurl}js/easyui/styles/default.css">
<%@ include file="/WEB-INF/views/common_css.jsp"%>
<%@ include file="/WEB-INF/views/common_js.jsp"%>

<script type="text/javascript">
	/*部门岗位菜单联动  */
	$(function() {
		$("#department").change(function() {
			$("#department option").each(function(i, o) {
				if ($(this).attr("selected")) {
					$(".job").removeAttr("name"); //移除属性name
					$(".job").css('display','none');
					$(".job").eq(i).css('display','block');
					$(".job").eq(i).attr('name','userJobId');
				}
			});
		});
		$("#department").change();
	});
	
	 /* 表单异步提交 */
	 $(function(){
		 
		 /* 表单校验 */
		 $('.mustW').validatebox({
			    required:true
		 });
		 
		 
		 /* 校验后提交 */
		 $("#submit").click(function(){
	        //调用表单插件的'submit'方法提交
	          $('#itemForm').form('submit', {
	              url:"${pageContext.request.contextPath }/user/save",
	              onSubmit: function(){
	                  //进行表单验证
	                  //如果返回false阻止提交
	                  return $('#itemForm').form('validate');
	              },
	              success:function(returnedDate){
	            	  if(returnedDate=="success"){
		            		 $.messager.confirm('修改用户', '修改成功！是否关闭?', function(r){
		         				if (r){
		         					//关闭弹出修改框
		         					parent.closemodalwindow();
		         					//选中创建的列表框（并刷新）
		         					parent.parent.$('#tabs').tabs('select','用户管理');
		         					
		         				}
		         			});
	            	 }else{
	            		 $.messager.alert('修改用户',returnedDate,'info');
	            	 }
	              }
	          });
		 });
     });
	 
	 
</script>
</head>
<body>
	<form:form id="itemForm" method="POST" modelAttribute="user">
		<br/><br/>
		<table width="50%" border=1 align="center">
			<tr>
				<td align="right">登录账号:&nbsp;</td>
				<td>
					<c:if test="${user.usercode==null }">
						<input type="text" name="usercode" required="true" class="mustW"/>
					</c:if>
					<c:if test="${user.usercode!=null }">
						<form:hidden path="userId"/>
						<input type="hidden" name="_method" value="PUT">
						<input type="text" name="usercode"
							value="${user.usercode }" readonly="readonly"/>
					</c:if>
				
				</td>
			</tr>
			<c:if test="${user.usercode!=null }">
				<tr>
					<td align="right">重置密码:&nbsp;</td>
					<td>
					<input type="radio" name="password" value="0" checked="checked"/>否
					<input type="radio" name="password" value="1" />是
					&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
					<font color="red"><b>(重置密码为：111111)</b></font>
					</td>
				</tr>
			</c:if>
			<tr>
				<td align="right">用户名称:&nbsp;</td>
				<td><input type="text" name="username"
					value="${user.username }" class="mustW" /></td>
			</tr>

			<tr>
				<td align="right">所属部门:&nbsp;</td>
				<td><select id="department">
						<c:forEach items="${vDepartments }" var="department">
							<c:if test="${department.departmentId == job.jobDepartmentId }">
								<option value="${department.departmentId }" selected="selected">${department.departmentName }</option>
							</c:if>

							<c:if test="${department.departmentId != job.jobDepartmentId }">
								<option value="${department.departmentId }">${department.departmentName }</option>
							</c:if>

						</c:forEach>
				</select></td>
			</tr>

			<tr>
				<td align="right">所属岗位:&nbsp;</td>
				<td>
					<c:forEach items="${vDepartments }" var="department">
						<select class="job" name="userJobId">
							<c:forEach items="${department.jobs }" var="jobs">
								<c:if test="${user.userJobId == jobs.jobId }">
									<option value="${jobs.jobId }" selected="selected">${jobs.jobName }</option>
								</c:if>
	
								<c:if test="${user.userJobId != jobs.jobId }">
									<option value="${jobs.jobId }">${jobs.jobName }</option>
								</c:if>
							</c:forEach>
						</select>
					</c:forEach>
					</td>
			</tr>
			
			<tr>
				<td align="right">所附角色:&nbsp;</td>
				<td><!--name=userRoles  -->
					<form:checkboxes path="userRoles" items="${roles}" />
				</td>
			</tr>
			<c:if test="${user.usercode!=null }">
				<tr>
					<td align="right">创建时间:&nbsp;</td>
					<td><fmt:formatDate value="${user.createtime}"
							pattern="yyyy-MM-dd HH:mm:ss" /></td>
				</tr>
			</c:if>
			<tr>
				<td align="right">是否锁定:&nbsp;</td>
					<%
						HashMap<Integer, String> locked = new HashMap<Integer, String>();
						locked.put(0, "否");
						locked.put(1, "是");
						request.setAttribute("locked", locked);
					%>
				<td>
					<form:radiobuttons path="locked" items="${locked }"/>
				</td>
			</tr>
		</table>
		<br/>
		<div align="center">
			<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-save'" id="submit">保存</a>
		</div>

	</form:form>
</body>

</html>